<?php

namespace app\admin\model\jdy;

use think\Model;

class News extends Model
{
    // 表名
    protected $name = 'jdy_news';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'state_text',
        'type_text',
        'lastdevicestarttime_text'
    ];
    

    
    public function getStateList()
    {
        return ['0' => __('State 0'),'1' => __('State 1')];
    }     

    public function getTypeList()
    {
        return ['註冊' => __('註冊'),'工作提醒' => __('工作提醒'),'裝置狀態' => __('裝置狀態'),'保固到期' => __('保固到期'),'其它' => __('其它')];
    }     


    public function getStateTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLastdevicestarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['lastdevicestarttime']) ? $data['lastdevicestarttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setLastdevicestarttimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
